<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<div class="row">
    <div class="col-md-12"  >
    	<div class="box box-primary">
    		<div class="box-header with-border">
    			<h3 class="box-title">
    			
    			</h3>
    			<div class="box-tools pull-right" id="workOrderGridTB_${uuid}">
    				
			    		<button class="btn btn-sm btn-success addBtn">
			    			<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加
			    		</button>
			    		<button class="btn btn-sm btn-primary editBtn">
			    			<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改
			    		</button>
			    		<button class="btn btn-sm btn-danger delBtn">
			    			<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除
			    		</button>
    			</div>
    		</div>
    		<div class="box-body">
            	 <table id="workOrderGrid_${uuid}">
            	 
            	 </table>
            </div>
    	</div>
    </div>
</div>
<script type="text/javascript">

    $(function () {
        var uuid = '${uuid}';
        
        var _workOrderGridTB=$("#workOrderGridTB_"+uuid);
        
        var workOrderGrid = $("#workOrderGrid_"+uuid).bootstrapTable({
        	url:ctx + "/workOrderAct/queryWorkOrder.do",
        	columns:[
				{field: '_id',checkbox:true},
                {title: '工单类型', field: 'WORKORDERTYPE', width: "210px"},
                {title: '工单名称', field: 'WORKORDERNAME'}
        	],
        	onClickRow:function(row){
        		var id=row.id;
        	}
        });
        
        _workOrderGridTB.find(".addBtn").click(function(){
        	/**
        	var sub = top.webUtils.topicSubscribe("workOrder.edit.success", function (args) {
                dialog.close();
                workOrderGrid.bootstrapTable("refresh");
            });
            var dialog = editWorkOrder({
                onClose: function () {
                    sub.remove();
                }
            });**/
        	var uuid=webUtils.uuid();
    		//webUtils.topicSubscribe("form.afterBuild",wiseMen.scheduler.taskScheduler.afterFormBuild,true);
    		var d=webUtils.dialog({
    			url:ctx+"/dataModelDefAct/editTpl.do?dms=DM_WORK_ORDER&winId="+uuid,
    			onremove:function(){
    				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
    			},
    			onshow:function(){
    				setTimeout('alert($("button[id*=submitBt]").length)',1000);
    			}
    		});
    		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
    			workOrderGrid.bootstrapTable("refresh");
    			d.close();
    		},true);
    		//alert($("form[id*=formView]").length);
        });
        
        _workOrderGridTB.find(".editBtn").click(function(){
        	var rows=workOrderGrid.bootstrapTable("getSelections");
        	if(rows && rows.length>0){
        		var sub = top.webUtils.topicSubscribe("workOrder.edit.success", function (args) {
            		dialog.close();
            		workOrderGrid.bootstrapTable("refresh");
                });
        		var row=rows[0];
        		var dialog= editWorkOrder({
                	id:row.id,
                    onClose: function () {
                        sub.remove();
                    }
                });
        	} else {
        		webUtils.alert("请选择需要编辑的数据");
            }
            
        });
        
        _workOrderGridTB.find(".delBtn").click(function(){
        	var rows=workOrderGrid.bootstrapTable("getSelections");
        	if(rows && rows.length>0){
        		webUtils.confirm("删除后将不可恢复，请问是否继续?", function(result) {
					if(result){
						var selecteds = [];
		                $.each(rows, function (i, n) {
		                    selecteds.push(n.id);
		                });
		                $.post(ctx + "/funcPointAction/delFuncPoint.do", {
		                    ids: selecteds.join(",")
		                }, function (data) {
		                    if (data.success) {
		                    	funcPointGrid.bootstrapTable("refresh");
		                    } else {
		                    	webUtils.alert(data.msg);
		                    }
		                }, 'json');
					}
        		});
        		
        	} else {
        		webUtils.alert("请选择需要删除的数据");
            }
            
        });
        
    });
</script>

